package com.spzx.user.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.user.api.RemoteUserInfoService;
import com.spzx.user.api.domain.UpdateUserLogin;
import com.spzx.user.api.domain.UserInfo;
import jakarta.servlet.ServletException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * projectName: spzx-parent
 *
 * @author: 王宝贵
 * time: 2024/10/13 16:35 周日
 * description:
 */
@Slf4j
@Component

public class RemoteUserInfoFallbackFactory implements FallbackFactory<RemoteUserInfoService> {


    @Override
    public RemoteUserInfoService create(Throwable cause) {

        log.error("用户登陆服务调用失败 ："+cause.getMessage());

        return new RemoteUserInfoService() {
            @Override
            public R<UserInfo> getUserInfo(String username, String source) {
                return R.fail("根据用户名获取用户信息,异常是：" +cause.getMessage());
            }

            @Override
            public R<Boolean> updateUserLogin(UpdateUserLogin updateUserLogin, String source) {
                return R.fail("更新用户登陆信息,异常是：" +cause.getMessage());
            }

            //用户注册
            @Override
            public R<Boolean> register(UserInfo userInfo, String source) throws ServletException {
                return R.fail("注册用户,异常是：" +cause.getMessage());
            }

        };
    }
}